//
//  BlogConnection.m
//  HanHan
//
//  Created by zou leeging on 10-10-24.
//  Copyright 2010 apple. All rights reserved.
//

#import "BlogConnection.h"


@implementation BlogConnection
@synthesize delegate;


-(void)performGetBlog:(NSString *)blogURL {

	//blogURL = [blogURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
	NSURL *url = [NSURL URLWithString:blogURL];
	
	NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
	
	NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
	
	[request release];
	
	if (connection) {
		
		NSLog(@"connection seccess!");
		receivedData = [[NSMutableData data] retain];
		
		//[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
	}
	else {
		NSLog(@"sfewfawef");
	}
	
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
	receivedData.length = 0;
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
	[receivedData appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
	[receivedData release];
	[connection release];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
	
	[delegate blogConnection:self didReceivedData:receivedData];
	
	NSLog(@"connection finish");
	
	[receivedData release];
	[connection release];
	
}

@end
